﻿using Pay.DTO;
using Pay.IService;
using Pay.TO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace Pay.Token.Controllers.Api
{
    /// <summary>
    /// 店铺管理
    /// </summary>
    [RoutePrefix("shop")]
    public class ShopInfoController : BaseController
    {
        private IShopInfoService _iShopInfoService;
        private ISettingService _iSettingService;
        public ShopInfoController(IShopInfoService iShopInfoService, ISettingService iSettingService) {
            _iShopInfoService = iShopInfoService;
            _iSettingService = iSettingService;
        }
        /// <summary>
        /// 新增修改店铺
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [Route("update_shop"), HttpPost]
        public ResultMessage<bool> UpdateShop(shop_info_dto model) {
            if (!ModelState.IsValid)
                return ResultToJson.Json<bool>(ModelError);
            model.id = UserId;
            bool result = _iShopInfoService.Save(model);
            return  ResultToJson.Json(result ? "保存成功" : "保存失败", result);
        }
        /// <summary>
        /// 获取店铺信息
        /// </summary>
        /// <returns></returns>
        [Route("get_shop"), HttpGet]
        public ResultMessage<shop_info_dto> GetShop() {
            var shop = _iShopInfoService.GetShopById(UserId);
            shop.url = t_RequestMethod.token_url + "/ShopInfo/ShopManage";
            return ResultToJson.Json(shop);
        }
    }
}
